Parallel Haskell: the Vectorisation Monad
نویسنده
چکیده
It has long been known that some of the most common uses of for and while-loops in imperative programs can easily be expressed using the standard higher-order functions fold and map. With this correspondence as a starting point, we derive parallel implementations of various iterative constructs, each having a better complexity than their sequential counterparts, and explore the use of monads to guarantee the soundness of the parallel implementation. As an aid to the presentation of the material, we use the proposed syntax for parallel Haskell 27] ((gure 1) as a vehicle in which imperative functional programs will be expressed. Surprisingly, incorporating imperative features into a purely functional language has become an active area of research within the functional programming community 30, 24, 36, 20]. One of the techniques gaining widespread acceptance as a model for imperative functional programming is monads 38, 37, 26]. Typically monads are used to guarantee single threaded-ness, enabling side eeects to be incorporated into a purely functional language without losing referential transparency. We take a diierent approach. First for-loops are translated into a monadic framework. Next, by ensuring that the monad satisses the programming identities usually associated with the successful vectorisation of imperative constructs, all well-typed for-loops in which the body is expressed using the vectorisation monad can be parallelised. The technique is not just restricted to a data-parallel environment. It could be implemented by a divide and conquer technique on a multi-processor platform, or by a parallel implementation of graph reduction such as that ooered by the GRIP 12] machine. 1 Background \ `Should declarative languages be mixed with imperative languages?', clearly has the answer that they should, because at the moment we don't know how to do everything in pure declarative languages."|C. Strachey, 1966 22]. The work presented in this paper uses a model of parallel computation based upon the Bird Meertens Formalism 6]. To make things simple, all parallelism is expressed in terms of a O(1) complexity map function, and O(log N) complexity fold and scan functions which both require an associative operator. Unlike our earlier work, we use the BMF as is|all the operations presented here can be interpreted as though they were being expressed on lists. This stance contradicts our earlier paper 15] in which we said that lists were unsuitable for data-parallel evaluation in a non-strict language. We still believe this to be true, but we have tried to …
منابع مشابه
Parallel Haskell: the Vectorisation Monad 2 Parallelising Simple Loops 2 2 Parallelising Simple Loops
It has long been known that some of the most common uses of for and while-loops in imperative programs can easily be expressed using the standard higher-order functions fold and map. With this correspondence as a starting point, we derive parallel implementations of various iterative constructs, each having a better complexity than their sequential counterparts, and explore the use of monads to...
متن کاملPartial Vectorisation of Haskell Programs
Vectorisation for functional programs, also called the flattening transformation, relies on drastically reordering computations and restructuring the representation of data types. As a result, it only applies to the purely functional core of a fully-fledged functional language, such as Haskell or ML. A concrete implementation needs to apply vectorisation selectively and integrate vectorised wit...
متن کاملThe Vectorisation Monad
Traditionally a vectorising compiler matches the iterative constructs of a program against a set of predeened templates. If a loop contains no dependency cycles then a map template can be used; other simple dependencies can often be expressed in terms of fold or scan templates. This paper addresses the template matching problem within the context of functional programming. A small collection of...
متن کاملA Monadic Calculus for Parallel Costing of a Functional Language of Arrays
Vec is a higher-order functional language of nested arrays, which includes a general folding operation. Static computation of the shape of its programs is used to support a compositional cost calculus based on a cost monad. This, in turn, is based on a cost algebra, whose operations may be customized to handle diierent cost regimes, especially for parallel programming. We present examples based...
متن کاملAccumulating bindings
We give a Haskell implementation of Filinski’s normalisation by evaluation algorithm for the computational lambda-calculus with sums. Taking advantage of extensions to the GHC compiler, our implementation represents object language types as Haskell types and ensures that type errors are detected statically. Following Filinski, the implementation is parameterised over a residualising monad. The ...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
عنوان ژورنال:
دوره شماره
صفحات -
تاریخ انتشار 1993